#!/usr/bin/env python
#-*- coding:utf-8 -*-
# author:Administrator
# datetime:2019/11/25 13:20
# software: PyCharm
# Email:zhou.haitao@technosolutions.cn
__auther__ = "Kael"

import os
import pandas as pd


RAW_FILE_PATH= "./data_without"

TARGET_FILE_NAME="./除醛酮target.csv"
# HEAD_TITLE = "时间,站点,甲醛,乙醛,丙烯醛,丙酮,丙醛,丁烯醛,甲基丙烯醛,2-丁酮,正丁醛,苯甲醛,戊醛,间甲基苯甲醛,己醛,大气压（kPa）,气温（℃）,湿度（%）,采样期间主导风向\r"

def station_name(sheet_name):
    if sheet_name==0:
        return   "阅海楼（背景点）"
    elif sheet_name==1:
        return "德源药业"
    elif sheet_name==2:
        return "胡沟管理处"
    else:
        return "矿山设计院"



def signal_file_process(file_name,sheet_name,sigle_station=True):

    df = pd.read_excel(file_name,sheet_name)
    data=[]

    data.append("20"+ df.iloc[8,1][0:12])
    if sigle_station:
        data.append("市站")
    else:
        data.append(station_name(sheet_name))

    for i in range(104):
        data.append( df.iloc[i+10,4])



    data.append( df.iloc[4,2])
    data.append( df.iloc[4,4])
    data.append( df.iloc[4,6])
    data.append( df.iloc[5,2])

    return str(data).rstrip(']').lstrip('[')+"\r"

def main_process(files_path,f_obj):
    for file_name in os.listdir(files_path):
        print(file_name)
        file_path = os.path.join(files_path,file_name)

        if "其它" in file_name:
            print(file_name)
            for i in range(4):
                f_obj.write(signal_file_process(file_path, i, False))
        else:
            f_obj.write(signal_file_process(file_path,0,True).replace("'","").replace("'",""))

if __name__ == '__main__':
    # print(signal_file_process("F:\PycharmProjects\JiPing_project\data_without\连云港4月1日-除醛酮.xlsx", 0,True))

    f_obj = open(TARGET_FILE_NAME,"w")
    # f_obj.write(HEAD_TITLE)

    main_process(RAW_FILE_PATH,f_obj)
    f_obj.close()
